package com.mycompany.myproject.service;

import com.mycompany.myproject.bean.Car;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

//@Service("carService")
////@Scope("singleton")
////@Lazy
public class CarServiceImpl implements CarService,
		BeanNameAware, BeanClassLoaderAware, BeanFactoryAware,
		InitializingBean, DisposableBean {

	@Value("${application.name}")
	private String appName ;

	@Autowired
	private Car car;

	public CarServiceImpl(){
		System.out.println("CarServiceImpl() 构造函数");
	}

	//////  @Bean  注解  ////////
	public void  initMethod(){
		System.out.println("CarServiceImpl initMethod()  定制初始化");
	}

	public void  destroyMethod(){
		System.out.println("CarServiceImpl destroyMethod()  定制销毁");
	}

	////////////  @PostConstruct  @PreDestroy ///////////////
	@PostConstruct
	public void  postConstruct(){
		System.out.println("CarServiceImpl init() @PostConstruct 初始化");
	}

	@PreDestroy
	public void  preDestroy(){
		System.out.println("CarServiceImpl init() @PreDestroy , 销毁");
	}

	/////////// 实现 InitializingBean  DisposableBean 接口    //////////////
	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("CarServiceImpl afterPropertiesSet() 实现 InitializingBean 接口, 初始化");
	}

	@Override
	public void destroy() throws Exception {
		System.out.println("CarServiceImpl destroy() 实现 DisposableBean 接口, 销毁");
	}

	@Override
	public void setBeanClassLoader(ClassLoader classLoader) {
		System.out.println("CarServiceImpl setBeanClassLoader 调用");
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		System.out.println("CarServiceImpl setBeanFactory 调用");
	}

	@Override
	public void setBeanName(String name) {
		System.out.println("CarServiceImpl setBeanName 调用");
	}

	public String getAppName() {
		System.out.println("call getAppName()");
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	public Car getCar() {
		return car;
	}

	public void setCar(Car car) {
		this.car = car;
	}
}
